using System;

namespace PetShop.Domain.Model
{
	
	
	[Serializable]
	public class LineItemEntity {

		private int _LineItemId;
		private int _OrderId;
		private int _LineNum;
		private ItemEntity _Item;
		private Order _Order;
		private int _Quantity;
		private decimal _ListPrice;


		public virtual int OrderId
		{
			get
			{
				return _OrderId;
			}
			set
			{
				_OrderId = value;
			}
		 
		}

		public virtual int LineNum
		{
			get
			{
				return _LineNum;
			}
			set
			{
				_LineNum = value;
			}
		}

		public virtual ItemEntity Item
		{
			get
			{
				return _Item;
			}
			set
			{
				_Item = value;
			}
		}
	  

		public virtual Order Order
		{
			get
			{
				return _Order;
			}
			set
			{
				_Order = value;
			}
		}

		public virtual int Quantity
		{
			get
			{
				return _Quantity;
			}
			set
			{
				_Quantity = value;
			}
		}

		public virtual decimal ListPrice
		{
			get
			{
				return _ListPrice;
			}
			set
			{
				_ListPrice = value;
			}
		}



		protected bool Equals(LineItemEntity entity)
		{
			if (entity == null) return false;
			if (!base.Equals(entity)) return false;
			if (!Equals(_OrderId, entity._OrderId)) return false;
			return true;
		}

		public override bool Equals(object obj)
		{
			if (ReferenceEquals(this, obj)) return true;
			return Equals(obj as LineItemEntity);
		}

		public override int GetHashCode()
		{
			int result = base.GetHashCode();
			result = 29 * result + _OrderId.GetHashCode();
			return result;
		}


		public LineItemEntity(){}


		public LineItemEntity( int qty,  ItemEntity item, Order order)
		{
			this._Item = item;
		  
			this._Order = order;
		 
			this._Quantity = qty;

			this._ListPrice = item.ListPrice;
		}

		public decimal SubTotal {
			get 
			{ 
				if (this._Item != null)
				{
					return this._Item.ListPrice * _Quantity;
				}
				else
				{
					return 0;
				}
				 
			}
		}

		public virtual int LineItemId
		{
			get { return _LineItemId; }
			set { _LineItemId = value; }
		}
	}
}